// 1.引入公用样式表
require("../../assets/css/index.less");
// require("../../assets/fonts/iconfont.css")

// 2.引入当前样式表
require("./starTraining.less");

// 引入插件

// 3.引入公用js模块
let validator = require("../../utils/validator.js");
let https = require("../../utils/https.js");

// 4.引入工具函数
let dom = require("../../utils/dom.js");
dom.ready(function () {

	dom.goTo("#goBack", "training");
	dom.goTo("#end", "training");
	// 蒙层
	dom.addEvent("#start", function () {
		dom.$("#mask").style.display = "block";
	});
	dom.addEvent("#continue", function () {
		dom.$("#mask").style.display = "none";
	});



	// 获取视频信息地址相关
	function getVideoUrl(selector, selector2) {
		let fragments;
		function getCourse() {
			https.get(`/api/train/courseDetail${location.search}`, function (res) {
				if (res.errno == 0) {
					fragments = res.data.fragments;
					// 渲染
					dom.$(selector).src = https.BASE_URL + fragments[0].videoUrl;
					dom.$(selector2).textContent = fragments[0].title;
					// console.log(fragments[0].title);
				}
			});
		}
		getCourse();
		let num = 0;
		dom.$("#last").addEventListener("click", function () {
			num--;
			if (num <= 0) {
				num = 0;
			}
			dom.$(selector).src = https.BASE_URL + fragments[num].videoUrl;
			dom.$("#part").textContent = num + 1;
			dom.$(selector2).textContent = fragments[num].title;
		});
		dom.$("#next").addEventListener("click", function () {
			num++;
			if (num >= 3) {
				num = 3;
			}
			dom.$(selector).src = https.BASE_URL + fragments[num].videoUrl;
			dom.$("#part").textContent = num + 1;
			dom.$(selector2).textContent = fragments[num].title

		});
	}
	getVideoUrl("#videoTxt", "#courseTitle")
	getVideoUrl("#videoTxt2", "#courseTitle2")

});
